import pygame
from pygame.sprite import Sprite

class Badball(Sprite):
    def __init__(self, ai_settings, screen):
        #初始化敌人并设置起始位置
        super(Badball, self).__init__()
        self.screen = screen
        self.ai_settings = ai_settings
        #加载敌人图像，设置其rect属性
        self.image = pygame.image.load("C:/Users/Administrator/AppData/Local/Programs/Python/Python37/images/enemy1.png").convert_alpha()
        self.rect = self.image.get_rect()

        #每个敌人初始位置在左上角附近
        self.rect.x = self.rect.width
        self.rect.y = self.rect.height
        #在指定位置绘制敌人
        self.x = float(self.rect.x)
    def blitme(self):
        self.screen.blit(self.image, self.rect)
    
    def check_edges(self):
        #检查敌人是否位于屏幕边缘
        screen_rect = self.screen.get_rect()
        if self.rect.right >= screen_rect.right:
            return True
        elif self.rect.left <= 0:
            return True
    def update(self):
        self.x += (self.ai_settings.badball_speed_factor * self.ai_settings.fleet_direction)
        
        self.rect.x = self.x
        
